home *** CD-ROM | disk | FTP | other *** search
- /* Exception handling.
-
- 94/01/19 aih - defined ExceptionTryType in ExceptionLib.h
- - added some comments to ExceptionLib.h
- 94/01/12 aih - added a few functions for setting information describing
- a failure
- 94/01/10 aih - made exception data a global variable
- 93/11/16 aih - fixed an error in the setup code which didn't properly
- reset gExecetion.jmpenv after a failure
- - added a comment describing a _try structure
- 93/10/26 aih - simplified macros a bit, fixed bug with prior bug fix...
- 93/10/23 aih - fixed bug with recursive failures/retries
- 93/10/19 aih - improved error reporting
- 93/03/?? aih - created */
-
- #include <string.h>
- #include <PrintTraps.h>
- #include "ErrorLib.h"
- #include "ExceptionLib.h"
-
- ExceptionType gException; /* information about current exception */
-
- void FailActionSet(short action)
- {
- gException.action = action;
- }
-
- void FailObjectSet(const CStr255 object)
- {
- *gException.object = 0;
- if (object)
- strcpy(gException.object, object);
- }
-
- void FailExplanationSet(const CStr255 explanation)
- {
- *gException.explanation = 0;
- if (explanation)
- strcpy(gException.explanation, explanation);
- }
-
- void FailInfoSet(short action, const CStr255 object, const CStr255 explanation)
- {
- FailActionSet(action);
- FailObjectSet(object);
- FailExplanationSet(explanation);
- }
-
- void FailInfoClear(void)
- {
- FailInfoSet(0, NULL, NULL);
- }
-
- void FailClear(void)
- {
- gException.err = noErr;
- FailInfoClear();
- }
-
- void FailDisplay(void)
- {
- if (gException.err != userCanceledErr) {
- ErrorDisplay(gException.err, gException.action,
- gException.object, gException.explanation);
- }
- }
-
- OSErr FailReason(void)
- {
- return(gException.err);
- }
-
- void FailOSErr(OSErr err)
- {
- if (err) {
- if (err == iPrAbort)
- err = userCanceledErr;
- if (! gException.err)
- gException.err = err;
- RAISE;
- }
- }
-
- void FailMemError(void)
- {
- FailOSErr(MemError());
- }
-
- void FailResError(void)
- {
- FailOSErr(ResError());
- }
-
- void FailPrError(void)
- {
- FailOSErr(PrError());
- }
-
- void FailNIL(void *p)
- {
- if (! p) FailOSErr(MemError() ? MemError() : memFullErr);
- }
-
- void FailNILRes(void *p)
- {
- if (! p) FailOSErr(ResError() ? ResError() : resNotFound);
- }
-
-